Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
getElementById that contains "abc" android onbackpressed

this is my onBackPressed:

@Override
    public void onBackPressed() {
        if (Config.EXIT_APP_BY_BACK_BUTTON_ALWAYS) {

            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl("javascript:(function(){"+
                    "l=document.getElementById('sdf_1422');"+
                    "e=document.createEvent('HTMLEvents');"+
                    "e.initEvent('click',true,true);"+
                    "l.dispatchEvent(e);"+
                    "})()");

}}

This works very well but the problem is that my page contains a lot of div's of sdf_1422, sdf_1423, sdf_1424, and so on. Can you help my to get all the sdf_, and click them.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can get all the elements you are looking for with document.querySelectorAll("div[id^=sdf_]") This is looking for all divs with id starting with sdf_ . This function returns a nodelist.

You can iterate a nodelist and add an event to every node:

let list = document.querySelectorAll("div[id^=sdf_]");
list.forEach(element => { element.addEventListener('click', () => {}) })
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda